class TagsController < ApplicationController
  before_filter :find_tag, :except => [ :index ]
  before_filter :login_required, :only => [ :destroy, :delete ]

  # maps to /tags - named route of tags_url
  # HTTP verb: GET  
  def index
    @tags = Tag.find(:all, :order => 'name')

    respond_to do |format|
      format.html
      format.xml  { render :xml => @tags.to_xml }
    end
  end

  # maps to /tags/:id - named route of tag_url(tag_object)
  # HTTP verb: GET
  def show
  end

  def delete
  end

  def destroy
    @tag.destroy if request.delete?
    redirect_to tags_url
  end
  
  protected
    def find_tag
      @tag = Tag.find(params[:id])
    end

    # only admin can delete tags
    def authorized?
      current_user.login == 'admin'
    end
end
